<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'adminForm',
    'type' => 'horizontal',
    'enableAjaxValidation' => false,
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
    ),
    'method' => 'post',
    'htmlOptions' => array('class' => 'table-bordered form-horizontal well'),
        ));
    if($model){
        
        $word = json_decode($model->word);
        $trans = json_decode($model->translate);
    }
?>
<fieldset>
    <?php echo $form->textFieldRow($model, 'name', array('class' => 'span5', 'maxlength' => 255)); ?>
    <div class="control-group "><label class="control-label required" for="RVideo_name"><b>Thêm lời dịch</b> <span class="required">*</span></label>
        <div class="controls">
            <button class="btn add_trans" >Thêm lời dịch</button>


        </div></div>
    <div class="row-fluid" style="width: 70%;
         margin: 5px auto;">
        <div class="span6" style="text-align: center">
            <b>Câu</b>
            <div class="row-fluid">
                <div class="control-group"><label class="control-label required" for="RVideo_name"></label>
                    <div class="controls_word">
                        <br>
                        <?php                          
                        if(is_array($word)){
                            foreach($word as $k=>$v){
                                
                                echo "<textarea style='height:70px;margin:3px' class='num".$k."' name='word[".$k."]'>".$v."</textarea>";
                                
                            }
                        }?>
                    </div>

                </div>
            </div>

        </div>

        <div class="span6" style="border-left:1px solid #000;text-align: center">
            <b>Lời dịch</b>
            <div class="row-fluid">
                <div class="control-group "><label class="control-label required" for="RVideo_name"></label>
                    <div class="controls_trans">
                        <br>
                        <?php if(is_array($trans)){
                            foreach($trans as $k=>$v){
                                echo "<textarea style='height:70px;margin:3px' class='num".$k."' name='trans[".$k."]'>".$v."</textarea><button onclick='del($(this))' class='del_text btn' id='num".$k."' >Xóa</button>";
                            }
                            }
                            ?>
                        <input type="hidden" value="<?php echo (@$k) ? $k : 0?>" class="num_word">
                    </div>
                </div>
            </div>

        </div>
    </div>
    <br>

    <?php echo $form->dropDownListRow($model, 'state', array(1 => 'Publish', 0 => 'UnPublish')); ?>

</fieldset>
<?php $this->endWidget(); ?>
<script>
    $().ready(function(){
        $(".add_trans").click(function(){
            sideA = $(".controls_word");
            sideB = $(".controls_trans");
            
            num = parseInt($(".num_word").val());
            num++;
            
            content_a = "<textarea style='height:70px;margin:3px' class='num"+num+"' name='word["+num+"]'></textarea>";
            content_b = "<textarea style='height:70px;margin:3px' class='num"+num+"' name='trans["+num+"]'></textarea><button onclick='del($(this))' class='del_text btn' id='num"+num+"' >Xóa</button>";
            sideA.append(content_a);
            sideB.append(content_b);
            $(".num_word").val((num));
            return false;
        })
    })
    function del(obj){
        id = obj.attr("id");
        $("textarea."+id).remove();
        $("button#"+id).remove();
    }
</script>
